﻿Public Partial Class Header
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not IsPostBack Then
        '    LinkLogout.Attributes.Add("OnClick", "javascript: return confirm('คุณต้องการที่จะออกจากระบบหรือไม่')")
        '    If (CheckSession()) Then
        '        Dim ds As DataSet = Session("UserData")
        '        If Not (ds Is Nothing) Then
        '            lbNameUser.Text = ds.Tables(0).Rows(0).Item("Name").ToString()
        '            lbRoleUser.Text = ds.Tables(0).Rows(0).Item("Role_name").ToString()
        '        Else
        '            Response.Redirect("../Form/Logon.aspx", True)
        '            ' ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", ";window.close();", True)
        '        End If

        '        'Literial Booking
        '        Dim drBooking As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Booking'") 'ให้ทำการ select เฉพาะ Mode Booking
        '        Dim HTML_MASTER_MENU As String = ""
        '        Dim HTML_MENU As String = ""
        '        Dim First As Boolean = True
        '        For Each dr As DataRow In drBooking
        '            If (dr("Show_Menu") & "" = "Y") Then
        '                If (First) Then
        '                    HTML_MENU = "<li><a  title='Booking' rel='dropmenu1_a'><span>Booking</span></a></li>"
        '                    HTML_MASTER_MENU = "<div id='dropmenu1_a' class='dropmenudiv_a'>"
        '                    First = False
        '                End If
        '                HTML_MASTER_MENU &= "<a href='../Form/" & dr("Path").ToString() & "?P1=" & dr("Edit_Menu").ToString() & "&P2=" & dr("Add_Menu").ToString() & "&P3=" & dr("Delete_Menu").ToString() & "'>" & dr("Menu_name").ToString() & "</a>"
        '            End If
        '        Next
        '        If Not (First) Then
        '            HTML_MASTER_MENU &= "</div>"
        '        End If

        '        'Literial Master
        '        First = True
        '        Dim drMaster As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Master'") 'ให้ทำการ select เฉพาะ Mode Master
        '        For Each dr As DataRow In drMaster
        '            If (dr("Show_Menu") & "" = "Y") Then
        '                If (First) Then
        '                    HTML_MENU &= "<li><a  title='Master' rel='dropmenu2_a'><span>Master</span></a></li>"
        '                    HTML_MASTER_MENU &= "<div id='dropmenu2_a' class='dropmenudiv_a'>"
        '                    First = False
        '                End If
        '                HTML_MASTER_MENU &= "<a href='../Master_Form/" & dr("Path").ToString() & "?P1=" & dr("Edit_Menu").ToString() & "&P2=" & dr("Add_Menu").ToString() & "&P3=" & dr("Delete_Menu").ToString() & "'>" & dr("Menu_name").ToString() & "</a>"
        '            End If
        '        Next
        '        If Not (First) Then
        '            HTML_MASTER_MENU &= "</div>"
        '        End If

        '        'Literial Report
        '        First = True
        '        Dim drReport As DataRow() = CType(Session("UserMenuRole"), DataSet).Tables(0).Select("Mode = 'Report'") 'ให้ทำการ select เฉพาะ Mode Master
        '        For Each dr As DataRow In drReport
        '            If (dr("Show_Menu") & "" = "Y") Then
        '                If (First) Then
        '                    HTML_MENU &= "<li><a  title='Report' rel='dropmenu3_a'><span>Report</span></a></li>"
        '                    HTML_MASTER_MENU &= "<div id='dropmenu3_a' class='dropmenudiv_a'>"
        '                    First = False
        '                End If
        '                HTML_MASTER_MENU &= "<a href='../Report/" & dr("Path").ToString() & "?P1=" & dr("Edit_Menu").ToString() & "&P2=" & dr("Add_Menu").ToString() & "&P3=" & dr("Delete_Menu").ToString() & "'>" & dr("Menu_name").ToString() & "</a>"
        '            End If
        '        Next
        '        If Not (First) Then
        '            HTML_MASTER_MENU &= "</div>"
        '        End If
        '        LiMenu.Text = HTML_MENU
        '        LiMenuBooking.Text = HTML_MASTER_MENU
        '    Else
        '        Session.Clear()
        '        Response.Redirect("../Form/Logon.aspx", True)
        '    End If
        'End If
    End Sub

    'Private Sub LinkHome_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkHome.Click
    '    Response.Redirect("../Form/MainPage.aspx", True)
    'End Sub

    'Private Sub LinkLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkLogout.Click
    '    Session.Clear()
    '    Response.Redirect("../Form/Logon.aspx", True)
    '    ' ScriptManager.RegisterClientScriptBlock(Me.Page, GetType(String), "myscript", ";window.close();", True)
    'End Sub

    Private Function CheckSession() As Boolean
        If ((Session("UserData") Is Nothing) Or (Session("Config") Is Nothing) Or (Session("UserMenuRole") Is Nothing) Or (Session("Role") Is Nothing)) Then
            Return False
        Else
            Return True
        End If
    End Function
End Class